using System.Collections;
using System.IO;
using Agile.Common.UI;

namespace Agile.Common
{
    /// <summary>
    /// Wrapper for FileInfo.
    /// </summary>
    public class AgileFileInfo : IAgileControlDetails
    {
        private readonly FileInfo _fileInfo;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="fileInfo">The FileInfo to wrap</param>
        private AgileFileInfo(FileInfo fileInfo)
        {
            _fileInfo = fileInfo;
        }

        /// <summary>
        /// The 'wrapped' File info object.
        /// </summary>
        public FileInfo FileInfo
        {
            get { return _fileInfo; }
        }

        /// <summary>
        /// Gets the name of the file
        /// </summary>
        public string Name
        {
            get { return FileInfo.Name; }
        }

        /// <summary>
        /// Gets the name of the file without the file extension.
        /// </summary>
        public string NameExcludingExtension
        {
            get { return FileInfo.Name.Replace(FileInfo.Extension, string.Empty); }
        }

        #region IAgileControlDetails Members

        /// <summary>
        /// Gets the value to display in the control
        /// </summary>
        string IAgileControlDetails.DisplayValue
        {
            get { return _fileInfo.Name; }
        }

        /// <summary>
        /// Gets any child objects.
        /// </summary>
        /// <example>A database table should return its collection of columns.</example>
        /// <remarks>Returns NULL if there are not any child objects.</remarks>
        IList IAgileControlDetails.ChildObjects
        {
            get { return null; }
        }

        /// <summary>
        /// Gets the color to use for the fore color
        /// </summary>
        /// <remarks>Must be an existing color, may be null</remarks>
        public string ForeColor
        {
            get { return null; }
        }

        /// <summary>
        /// Gets the color to use for the back color
        /// </summary>
        /// <remarks>Must be an existing color, may be null</remarks>
        public string BackColor
        {
            get { return null; }
        }

        #endregion

        /// <summary>
        /// Instantiate a new AgileFileInfo with the given FileInfo.
        /// </summary>
        /// <param name="fileInfo">The FileInfo to wrap</param>
        /// <returns></returns>
        public static AgileFileInfo Build(FileInfo fileInfo)
        {
            return new AgileFileInfo(fileInfo);
        }
        /// <summary>
        /// Override to get the full name of the file.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return _fileInfo.FullName;
        }
    }
}